<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .red {
        color: red;
      }
      .green {
        color: green;
      }
      .big-size {
        font-size: 30px;
      }
      .weight {
        font-weight: 900;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <h2>class绑定</h2>
      <!-- <p :class="show === 1 && 'red'">hello Vue!</p> -->
      <!-- <p v-bind:class="show === 1 ? 'red' : 'green'">hello Vue!</p> -->

      <!-- vue允许我们在:class里面直接写对象 -->
      <!-- key表示类名，value表示变量或者表达式 -->
      <!-- 如果类名出现了连字符或者下划线，需要给类名添加引号 -->
      <p :class="{ red: show === 1, 'big-size': big }">hello Vue!</p>
      <p :class="obj">hello Vue3!</p>
      <p :class="obj2">hello Vue3!!!</p>

      <!-- 绑定数组的语法 -->
      <p :class="[a, b]">绑定数组</p>

      <!-- :class是可以和class一起用的 -->
      <p class="abc" :class="a">class补充</p>
    </div>

    <script src="./lib/Vue3.js"></script>
    <script>
      const { createApp } = Vue;

      createApp({
        data() {
          return {
            show: 1,
            big: true,
            // showGreen: true,
            // weight: true,
            obj: { green: true, weight: true },
            a: "red",
            b: "weight",
          };
        },
        computed: {
          obj2() {
            return { red: this.show === 1, "big-size": this.big };
          },
        },
      }).mount("#app");
    </script>
  </body>
</html>
